package org.gdkm.util;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class BaseResult implements Serializable {


    private String result;
    private Object data;
    private String success;
    private Cursor cursor;
    private List<Error> errors;
    private static final String RESULT_OK = "ok";
    private static final String RESULT_NOT_OK = "not_ok";
    private static final String SUCCESS = "success";

    public static BaseResult ok() {
        return BaseResult.createBaseResult(RESULT_OK, null, SUCCESS, null,null);
    }

    public static BaseResult ok(Object data) {
        return BaseResult.createBaseResult(RESULT_OK, SUCCESS,data,null, null);
    }

    public static BaseResult notOk(List<BaseResult.Error> errors) {
        return BaseResult.createBaseResult(RESULT_NOT_OK, "","",  null,errors);
    }
    public static BaseResult Ok(Object data,Cursor cursor) {
        return BaseResult.createBaseResult(RESULT_NOT_OK, SUCCESS,data, cursor,null);
    }
    private static BaseResult createBaseResult(String result, String success,Object data,  Cursor cursor,List<Error> errors) {
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(success);
        baseResult.setResult(result);
        baseResult.setData(data);
        baseResult.setErrors(errors);
        baseResult.setCursor(cursor);
        return baseResult;
    }

    @Data
    public static class Cursor {
        private int total;
        private int offset;
        private int limit;
    }

    @Data
    @AllArgsConstructor
    public static class Error {
        private String filed;
        private String message;


    }
}
